<?php
        include_once 'xmlrpc.inc';
	include 'Session.php';
	class NewsInfo {
		private $news_out;
		public function __construct($news_out)
		{
			$this->news_out = $news_out;
		}
		public function getIdNews()
		{	
			return $this->news_out['id_news'];
		}
		public function getTitle()
		{
			return $this->news_out['title'];
		}
		public function getMsg()
		{
			return $this->news_out['contenuto'];
		}

	}
	class News {
		private $token_id;
		private $url_news_service;

		public function __construct() {
			$this->url_news_service = new xmlrpc_client("http://muovi.roma.it/ws/xml/news/2");
			$this->token_id = $_SESSION['token_id'];
		} 


		public function getNews() {
			$news_req = new xmlrpcmsg('news.Tutte', array( new xmlrpcval($this->token_id, "string"), new xmlrpcval("it", "string")));
			$result = $this->url_news_service->send($news_req);
			
			$news_info_out = array();
			if (!$result->faultCode())
			{
				$value_news_resp = $result->value();
				$resp = $value_news_resp->structMem("risposta");
				for ($i = 0; $i < $resp->arraySize(); $i++)
				{
					$val = $resp->arrayMem($i);
					$id_news = $val->structMem("id_news")->scalarVal();
					$id_categoria = $val->structMem("id_categoria")->scalarVal();
					$titolo = $val->structMem("titolo")->scalarVal();
					$contenuto = $val->structMem("contenuto")->scalarVal();
					$data_pubblicazione = $val->structMem("data_pubblicazione")->scalarVal();
					$n = array("id_news"=>$id_news,"title"=>$titolo,"contenuto"=>$contenuto); 
					$news_info = new NewsInfo($n);
					$news_info_out[] = $news_info;
				}
			}
			else
			{
				throw new Exception("Errore richiesta linee<br/>");
			}
			return $news_info_out;
		}
		
	}
?>
